USE [xRepair]
GO
IF OBJECT_ID('[dbo].[AddNewState]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[AddNewState]
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[AddNewState]
		 @StateAbbreviation	    NVARCHAR(5)
		,@StateName				NVARCHAR(255)
		,@CreatedAt				DATETIME = NULL
		,@CreatedBy				NVARCHAR(50)
		,@NewIdentity			INT = NULL OUTPUT
AS
BEGIN

	SET NOCOUNT ON;
	
	INSERT INTO [dbo].[States]
           ([StateAbbreviation]
		   ,[StateName]
		   ,[IsActive]
           ,[CreatedAt]
           ,[CreatedBy]
           )
     VALUES
           (@StateAbbreviation
           ,@StateName
           ,1
           ,@CreatedAt
           ,@CreatedBy
           )

	SELECT @NewIdentity = @@IDENTITY

END

GO


